// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TradingAction.java

package com.boci.clientapp.trading.action;

import com.boci.clientapp.main.*;
import com.boci.clientapp.trading.TradingScrPanel;
import com.boci.clientapp.trading.TrdReviewScrPanel;
import com.boci.clientapp.trading.handler.BalanceSummaryHandler;
import com.boci.clientapp.trading.handler.TradingHandler;
import com.boci.common.action.AbstractAction;
import com.boci.common.constant.RequestTypeConst;
import com.boci.common.util.*;
import java.util.HashMap;
import java.util.logging.Logger;

public class TradingAction extends AbstractAction
{

    public TradingAction()
    {
        strModName = "TRADING_MODULE";
        strScrName = "TRADING_SCREEN";
    }

    private void addExtraValues(HashMap pInpMap, String pActionType, boolean pHKMktFlag, String pOrderType)
    {
        if(!pHKMktFlag && pOrderType != null && pOrderType.equals("MKT"))
        {
            pInpMap.put("testValue", "GetQuote");
            pInpMap.put("testValue1", "GetQuote");
        } else
        {
            pInpMap.put("testValue", "ReviewBeforeSending");
            pInpMap.put("testValue1", "xxx");
        }
        if(!pHKMktFlag)
            pInpMap.put("userid", appServ.getUserID());
        pInpMap.put("select2", appServ.getAccountNo());
        if(pActionType.equals("BUY"))
            pInpMap.put("radiobutton", "BUY");
        else
        if(pActionType.equals("SELL"))
            pInpMap.put("radiobutton", "SELL");
    }

    public void doProcess(HashMap pInpMap, String pActionType)
    {
    	try{
	        appServ.setBusy(true);
	        TradingScrPanel trdPanel = (TradingScrPanel)appServ.getMainPanel().getPanel(strModName, strScrName);
	        TrdReviewScrPanel reviewPanel = (TrdReviewScrPanel)appServ.getMainPanel().getPanel(strModName, "REVIEW_TRADING_SCREEN");
	        if(pActionType.equals("BUY") || pActionType.equals("SELL"))
	        {
	            reviewPanel.resetDuplicateFlag();
	            String orderType = (String)pInpMap.get("ordtype");
	            if(trdPanel.getHKMktFlag())
	            {
	                addExtraValues(pInpMap, pActionType, true, orderType);
	                String strReqType = RequestTypeConst.BOCI_HK_TRADE_REVW_URL;
	                TradingHandler tradingHandler = new TradingHandler(strReqType);
	                reviewPanel.refresh(tradingHandler.reviewHKTrade(pInpMap));
	            } else
	            {
	                addExtraValues(pInpMap, pActionType, false, orderType);
	                String strReqType = RequestTypeConst.BOCI_US_TRADE_REVW_URL;
	                TradingHandler tradingHandler = new TradingHandler(strReqType);
	                reviewPanel.refresh(tradingHandler.reviewUSTrade(pInpMap));
	            }
	            appServ.getMainPanel().showScreen("TRADING_MODULE", "REVIEW_TRADING_SCREEN");
	        } else
	        if(pActionType.equals("CLEAR"))
	            trdPanel.clearText();
	        else
	        if(pActionType.equals("HK_MARKET"))
	            trdPanel.chgMarket(pActionType);
	        else
	        if(pActionType.equals("US_MARKET"))
	            trdPanel.chgMarket(pActionType);
	        else
	        if(pActionType.equals("SHOW BALANCE"))
	        {
	            HashMap map = new HashMap();
	            map.put("selectAcct", appServ.getAccountNo());
	            String strReqType = RequestTypeConst.BOCI_BALANCE_SIMPLE_URL;
	            BalanceSummaryHandler handler = new BalanceSummaryHandler(strReqType);
	            appServ.showBalanceDialog(handler.getBalanceSummary(map));
	        } else
	        if(pActionType.equals("GETQUOTE"))
	        {
	            String strCode = (String)pInpMap.get("symbol");
	            if(trdPanel.getHKMktFlag())
	                appServ.showGetQuoteInfo("HK_MARKET", strCode);
	            else
	                appServ.showGetQuoteInfo("US_MARKET", strCode);
	        }
    	}
        catch(AppException appEx)
        {
            logger.info(StringUtil.formatException(appEx));
            String strError = appEx.getMessage();
            if(appEx.getErrorCode().equals("STR_US_TRADE_ORDER_LIMIT"))
                strError = strError.replaceAll("%SIZE%", ClientAppLoader.getAppConfigurator().getAppConfig("US_ORDER_SIZE"));
            appServ.showErrorDialog(null, strError);
        }
        catch(Exception sysEx)
        {
            logger.severe(StringUtil.formatException(sysEx));
            appServ.showSysErrDialog();
        }
        finally
        {
            appServ.setBusy(false);
        }
        return;
    }

    String strModName;
    String strScrName;
}
